<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('医院科室列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse none">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <!--<li>-->
                        <!--<p>医院：</p>-->
                        <!--<select name="hospitalId" id="hospitalId" th:with="type=${@dep.depts(null,'220,270,290')}">-->
                        <!--<option th:each="dept : ${type}" th:text="${dept.deptName}" th:value="${dept.deptId}"-->
                        <!--th:field="*{dept.deptId}"></option>-->
                        <!--</select>-->
                        <!--</li>-->
                        <li>
                            <p>科室名称：</p>
                            <input type="text" name="deptName"/>
                        </li>
                        <li>
                            <p>负责人：</p>
                            <input type="text" name="deptUserName"/>
                        </li>
                        <li>
                            <p>类型：</p>
                            <select name="type" th:with="type=${@dict.getType('HOSP_DEPT_TYPE')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>电话：</p>
                            <input type="text" name="deptIphone"/>
                        </li>

                        <!--<li>-->
                        <!--<p>状态：</p>-->
                        <!--<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">-->
                        <!--<option value="">所有</option>-->
                        <!--<option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
                        <!--th:value="${dict.dictValue}"></option>-->
                        <!--</select>-->
                        <!--</li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="btnRefresh"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="yf:dept:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="yf:dept:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.UremoveAll()"
               shiro:hasPermission="yf:dept:uRemove">
                <i class="fa fa-remove"></i> 删除
            </a>

            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="yf:dept:remove">
                <i class="fa fa-remove"></i> 彻底删除
            </a>

            <a class="btn btn-primary multiple disabled" onclick="$.operate.URecoveryAll()"
               shiro:hasPermission="yf:dept:uRecovery">
                <i class="fa fa-history"></i> 恢复
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="yf:dept:export">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="yf:dept:export">
                <i class="fa fa-download"></i> 导出
            </a>

            <a class="btn btn-warning  multiple disabled hidden" onclick="packageImages()"
               shiro:hasPermission="yf:dept:export">
                <i class="fa fa-download"></i> 下载
            </a>

            <a class="btn btn-warning single disabled" onclick="$.operate.transitionHospital(null,'科室转机构')"  shiro:hasPermission="yf:dept:transition">
                <i class="fa fa-download"></i> 转机构
            </a>

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/js/qrcode.min.js}" ></script>

<!-- 打包下载插件 -->
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>-->
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>-->
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('yf:dept:edit')}]];
    var uRemoveFlag = [[${@permission.hasPermi('yf:dept:uRemove')}]];//标记删除
    var removeFlag = [[${@permission.hasPermi('yf:dept:remove')}]];//彻底删除
    var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
    var deptTypeList = [[${@dict.getType('HOSP_DEPT_TYPE')}]];

    var standardDeptCodes = [[${@dict.getType('yf_standard_dept_code')}]];  // 字典表：标准科室名称

    var qcode = [[${@permission.hasPermi('yf:dept:qCode')}]]
    //科室人员列表 护士 按钮
    var nurseDatas = [[${@permission.hasPermi('yf:nurse:view')}]];
    var prefix = ctx + "yf/dept";
    //修改为对象
    var hostid = sessionStorage.getItem("hospital_ids")
    //初始化logo
    $.department.init({
        logo_imgPath: '/profile/medical_waste_logo/' + hostid + '.jpg'
    })

    //转变医院
    function transitionHospital(id) {
        //    机构名称
        //    机构编号
        //    等级
        //    城市
        //    归属位置
        //    是否创建暂存点
        //    是否创建暂存点用户
        var url = ctx + "system/dept/transitionHospital/" + id
        $.modal.open("机构转换", url)
    }

    //Map转Json
    //    function MapTOJson(m) {
    //        var str = '{';
    //        var i = 1;
    //        m.forEach(function (item, key, mapObj) {
    //            if (item.logo != null)
    //                str += '"' + item.deptId + '":{"deptName":"' + item.deptName + '","logo":"' + item.logo + '"},';
    //            i++;
    //        });
    //        str = str.substring(0, str.length - 1) + '}';
    //        return str;
    //    }


    //todo 完善 删除标记后 不能修改信息


    $('#btnRefresh').click(function () {
        $.table.search(null, null, {
            hospitalId: hostid
        });
    })


    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/" + hostid,
            transitionHospital: ctx + "system/dept/toHospital/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            UremoveUrl: prefix + "/Uremove",
            URecoveryUrl: prefix + "/URecovery",
            exportUrl: prefix + "/export",
            modalName: "医院科室",
            rowStyle: rowStyle,//自定义行删除样式
            queryParams: queryParams,
            pageList: [20, 30, 50],
            pageSize: 20,
            // queryParams: {
            //         hospitalId: hostid,
            // },
            columns: [{
                checkbox: true
            },
                {
                    field: 'deptId',
                    title: '科室id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '科室名称'
                },
                {
                    field: 'deptUserName',
                    title: '负责人'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(deptTypeList, value);
                    }
                },
                {
                    field: 'deptTel',
                    title: '科室电话'
                },
                {
                    field: 'deptIphone',
                    title: '负责人电话'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'buildingNo',
                    title: '楼号'
                },
                {
                    field: 'standardDeptCode',
                    title: '标准科室代码'
                },
                {
                    field: 'standardDeptCode',
                    title: '标准科室名称',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(standardDeptCodes, value);
                    }
                },
                {
                    field: 'groupNo',
                    title: '分组编号'
                },
                {
                    field: 'groupName',
                    title: '分组名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<button type="button" class="btn btn-info btn-xs ' + qcode + '"  data-toggle="modal" data-target="#myModal6" onclick="$.department.preQRcode(\'' + row.deptName + '\',\'' + row.deptId + '\');"><i class="fa fa-qrcode"></i>二维码</button> ');
                        actions.push('<button type="button" class="btn btn-info btn-xs ' + qcode + '"   onclick="$.department.downQRcode(\'' + row.deptName + '\',\'' + row.deptId + '\');"><i class="fa fa-download"></i>二维码</button> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + uRemoveFlag + '" href="javascript:void(0)" onclick="$.operate.Uremove(\'' + row.deptId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')"><i class="fa fa-remove"></i>彻底删除</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + nurseDatas + '" href="javascript:void(0)" onclick="nursess(\'' + row.deptName + '\',\'' + row.deptId + '\');"><i class="glyphicon glyphicon-user"></i>护士</a> ');
                        return actions.join('');
                    }
                }]
        };


        $.table.init(options);


        $("#hospitalId").on('change', function () {
            options.createUrl = prefix + "/add/" + $(this).val();
            $.table.init(options)
        });


    });

    /*科室人员-列表*/
    function nursess(name, dept_id) {
        console.log(dept_id)
        var url = ctx + 'yf/nurse/' + dept_id;
        $.modal.openTab(name + "-人员管理", url);
    }


    // 分页查询条件
    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.hospitalId = sessionStorage.getItem("hospital_ids");
        return search;
    }


    //修改行标记删除的颜色
    function rowStyle(row, index) {
        if (row.delFlag == 2) {
            return {
                classes: 'delflag'
            }
        }
        return {};
    }

    //////////////////////**
    //
    //    $('#status').text('处理中。。。。。');
    //
    //    var imgs = $('img');
    //
    //    var imgBase64 = [];
    //    var imageSuffix = [];//图片后缀
    //    var zip = new JSZip();
    //    zip.file("readme.txt", "案件详情资料\n");
    //    var img = zip.folder("images");
    //
    //    for(var i=0;i<imgs.length;i++){
    //        var src = imgs[i].getAttribute("src");
    //        var suffix = src.substring(src.lastIndexOf("."));
    //        imageSuffix.push(suffix);
    //
    //        qrcode_path(imgs[i].getAttribute("src"))
    //            .then(function(base64){
    //                imgBase64.push(base64.substring(22));
    //
    //            },function(err){
    //                console.log(err);//打印异常信息
    //            });
    //
    //    }
    //    function tt(){
    //        setTimeout(function(){
    //            if(imgs.length == imgBase64.length){
    //                for(var i=0;i<imgs.length;i++){
    //                    img.file(i+imageSuffix[i], imgBase64[i], {base64: true});
    //                }
    //                zip.generateAsync({type:"blob"}).then(function(content) {
    //                    saveAs(content, "images.zip");
    //                });
    //                $('#status').text('处理完成。。。。。');
    //
    //            }else{
    //                $('#status').text('已完成：'+imgBase64.length+'/'+imgs.length);
    //                tt();
    //            }
    //        },100);
    //
    //    }
    //    tt();


</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>
